If ObjectProperty(Object_ID('dbo.opengiving_eventInsert_sp'), N'IsProcedure') Is Null
Begin
    Execute ('Create Procedure dbo.opengiving_eventInsert_sp As Print ''Hello World!''')
    RaisError('Procedure opengiving_eventInsert_sp created.', 10, 1);
End;
Go

Set ANSI_Nulls On;
Set Quoted_Identifier On;
Go

Alter Procedure dbo.opengiving_eventInsert_sp

        /* Declare Parameters */
          @eventName            varchar(50)
        , @startTime            smalldatetime
        , @endTime              smalldatetime
        , @address_street       varchar(50)
        , @address_city         varchar(50)
        , @address_state        char(2)
        , @address_zip          varchar(10)
        , @address_country      char(2)
        , @neighborhood_id      tinyint
        , @url                  varchar(255)
        , @briefDescription     varchar(64)
        , @fullDescription      varchar(255)
        , @organization_id      smallint
        , @contact_id           int
        , @volunteerMax         tinyint
        , @sameDayRegistration  bit
        , @registrationCutOff   smalldatetime
        , @isCancelled          bit
As
/*********************************************************************************
    Name:       opengiving_eventInsert_sp

    Author:     Michelle Ufford

    Purpose:    Inserts a record into the opengiving_event table.

    Notes:      Part of the OpenGiving open-source project, 
                http://opengiving.codeplex.com

    Called by:  admin tool

    Date        User    Description
    ----------------------------------------------------------------------------
    2009-05-05  MFU     Initial Release
*********************************************************************************
    Exec dbo.opengiving_eventInsert_sp
          @eventName            = 'My First Event'
        , @startTime            = '2009-01-01 9:00'
        , @endTime              = '2009-01-01 10:00'
        , @address_street       = '123 Some Place'
        , @address_city         = 'Cedar Rapids'
        , @address_state        = 'IA'
        , @address_zip          = '52402'
        , @address_country      = 'US'
        , @neighborhood_id      = 1
        , @url                  = 'http://opengiving.codeplex.com'
        , @briefDescription     = 'My first event.'
        , @fullDescription      = 'This is a long description.'
        , @organization_id      = 1
        , @contact_id           = 1
        , @volunteerMax         = 1
        , @sameDayRegistration  = 1
        , @registrationCutOff   = '2009-01-01'
        , @isCancelled          = 1;
*********************************************************************************/

Set NoCount On;
Set XACT_Abort On;
Set Ansi_Padding On;
Set Ansi_Warnings On;
Set ArithAbort On;
Set Concat_Null_Yields_Null On;
Set Numeric_RoundAbort Off;

Begin
    Begin Try
   
        /* Start a new transaction */
        Begin Transaction;

        Insert Into dbo.opengiving_event
        (
              eventName
            , startTime
            , endTime
            , address_street
            , address_city
            , address_state
            , address_zip
            , address_country
            , neighborhood_id
            , url
            , briefDescription
            , fullDescription
            , organization_id
            , contact_id
            , volunteerMax
            , sameDayRegistration
            , registrationCutOff
            , isCancelled
        )
        OutPut inserted.event_id
        Values
        (
              @eventName
            , @startTime
            , @endTime
            , @address_street
            , @address_city
            , @address_state
            , @address_zip
            , @address_country
            , @neighborhood_id
            , @url
            , @briefDescription
            , @fullDescription
            , @organization_id
            , @contact_id
            , @volunteerMax
            , @sameDayRegistration
            , @registrationCutOff
            , @isCancelled
        );

        /* If you have an open transaction, commit it */
        If @@TranCount > 0
            Commit Transaction;

    End Try
    Begin Catch

        /* Whoops, there was an error... rollback! */
        If @@TranCount > 0
            Rollback Transaction;

        /* Return an error message and log it */
        Execute dbo.dba_logError_sp;

    End Catch;

    Set NoCount Off;
    Return 0;
End
Go

Set Quoted_Identifier Off;
Go